package com.ljx.rabbit.controller;


import com.ljx.rabbit.domain.dto.ItemCommentDTO;
import com.ljx.rabbit.domain.dto.ItemCommentPage;
import com.ljx.rabbit.domain.po.Comment;
import com.ljx.rabbit.domain.po.HeadGoods;
import com.ljx.rabbit.domain.po.UserLikes;
import com.ljx.rabbit.domain.vo.CommentChildrenVO;
import com.ljx.rabbit.domain.vo.CommentVO;
import com.ljx.rabbit.domain.vo.ItemVo;
import com.ljx.rabbit.result.R;
import com.ljx.rabbit.service.IItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-21
 */
@RestController
@RequestMapping("/goods")
@CrossOrigin
@Slf4j
@Api(tags = "商品")
@RequiredArgsConstructor
public class ItemController {
    private final IItemService itemService;
    @ApiOperation(value = "获取商品详情")
    @GetMapping()
    public R<ItemVo> getGoodsDetail(@RequestParam Long id) {
        ItemVo itemVo =itemService.getDetail(id);
        return R.success(itemVo);
    }

    @ApiOperation(value = "获取热榜商品")
    @GetMapping("/hot")
    public R<List<HeadGoods>> getHotGoods(
            @RequestParam Long id,
            @RequestParam Integer type,
            @RequestParam Integer limit) {
        List<HeadGoods> hotGoods = itemService.getHotGoods(id,type,limit);
        return R.success(hotGoods);
    }

    @ApiOperation(value = "猜你喜欢")
    @GetMapping("/relevant")
    public R<List<HeadGoods>> getRelevantGoods(@RequestParam Integer limit){
        List<HeadGoods> relevantGoods = itemService.getRelevantGoods(limit);
        return R.success(relevantGoods);
    }

    @ApiOperation(value = "获取商品分页评价1级")
    @PostMapping("/comment")
    public R<List<CommentVO>> getComment(@RequestBody ItemCommentPage itemCommentPage){
        List<CommentVO> comments = itemService.getComments(itemCommentPage);
        return R.success(comments);
    }

    @ApiOperation(value = "点赞商品评论")
    @PutMapping("/comment/like")
    public R<Long> likeComment(@RequestParam String commentId){

        return R.success(itemService.likeCommentById(commentId));
    }
    @ApiOperation(value = "取消点赞商品评论")
    @PutMapping("/comment/dislike")
    public R<Long> dislikeComment(@RequestParam String commentId){

        return R.success(itemService.dislikeCommentById(commentId));
    }

    @ApiOperation(value = "回复商品评论 即创建2级评论")
    @PostMapping("/comment/reply")
    public R replyComment(@RequestBody ItemCommentDTO commentDTO){
        itemService.replyComment(commentDTO);
        return R.success();
    }

    @ApiOperation(value = "查看商品2级评论")
    @GetMapping("/comment/reply")
    public R<List<CommentChildrenVO>> getReplyComment(
            @RequestParam String commentId,
            @RequestParam Integer page,
            @RequestParam Integer pageSize){
        List<CommentChildrenVO> commentChildrenVOS = itemService.getReplyComment(commentId,page,pageSize);
        return R.success(commentChildrenVOS);
    }


}
